// bmpgl.js
export function BMPGL(ak) {
  return new Promise(function (resolve, reject) {
    if (window.BMapGL) {
      resolve(BMapGL)
    } else {
      window._init = function () {
        // eslint-disable-next-line
        resolve(BMapGL)
      }
      const script = document.createElement('script')
      script.type = 'text/javascript'
      script.src = `//api.map.baidu.com/api?v=1.0&type=webgl&ak=${ak}&callback=_init`
      script.onerror = reject
      document.head.appendChild(script)
    }
  })
}